package com.shareach.web.basic;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.commons.lang.StringUtils;

public abstract class BaseAskParameter implements IAskParameter {
	protected String trim(String value){
		if(!StringUtils.isBlank(value)){
			return value.trim();
		}else{
			return value;
		}
	}
	@SuppressWarnings("unchecked")
	protected <T> T getData(HashMap<String, Object> map,String filed){
		if(map.containsKey(filed)){
			return (T)map.get(filed);
		}else{
			return  null;
		}
	}
	protected Integer getInt(HashMap<String, Object> map,String filed){
		if(map.containsKey(filed)){
			if(map.get(filed) instanceof String ){
				if("".equals(map.get(filed))) return null;
				return Integer.parseInt((String)map.get(filed));
			}
			return (Integer)map.get(filed);
		}else{
			return  null;
		}
	}
	protected Long getLong(HashMap<String, Object> map,String filed){
		if(map.containsKey(filed)){
			if(map.get(filed) instanceof String ){
				if("".equals(map.get(filed))) return null;
				return Long.parseLong((String)map.get(filed));
			}
			return (Long)map.get(filed);
		}else{
			return  null;
		}
	}
	protected Double getDouble(HashMap<String, Object> map,String filed){
		if(map.containsKey(filed)){
			if(map.get(filed) instanceof String ){
				if("".equals(map.get(filed))) return null;
				return Double.parseDouble((String)map.get(filed));
			}
			return (Double)map.get(filed);
		}else{
			return  null;
		}
	}

	@SuppressWarnings("unchecked")
	protected <T> ArrayList<T> getArrayList(HashMap<String, Object> map,String field){
		if(map.containsKey(field)){
			return (ArrayList<T>)map.get(field);
		}else{
			return null;
		}
	}
	protected Object[] getArray(HashMap<String, Object> map,String field){
		if(map.containsKey(field)){
			return (Object[])map.get(field);
		}else{
			return null;
		}
	}
	public abstract void parseFromMap(HashMap<String,Object> map);
}
